import string
import time
from time import sleep

from selenium import webdriver
import random
from yurongtong_system_background.common.base import Base


login_url = "http://52.80.159.11:9510/formLogin"

class LoginPage(Base):


    # 登录
    login_ph = ('xpath', '//*[@id="appWrap"]/div[2]/div/div/div/div[2]/div/div[1]/div[2]/div[1]')
    login_phone = ('id', 'phone')
    login_code = ('id', 'code')
    login_submit = ('class name', 'components-front-login-LoginBox-Btn-__index__button--3StYq')

    assert_loc = ("xpath", '//*[@id="appWrap"]/div/div[1]/div/div/div[1]/div[1]')
    assert_loc1 = ("xpath", '//*[@id="appWrap"]/div[2]/div/div/div/div[2]/div/form/div[2]/div/div/div')



    def click_ph(self):
        self.click(self.login_ph)

    def input_phone(self, phone=""):
        self.sendKeys(self.login_phone, phone)

    def input_code(self, code=""):
        self.sendKeys(self.login_code, code)

    def click_submit(self):
        self.click(self.login_submit)

    def is_login_success(self, _text):
        return self.is_text_in_element(self.assert_loc, _text)

    def is_login_fail(self, _text):
        return self.is_text_in_element(self.assert_loc1, _text)

    #  登录系统后台
    def login(self, phone="15823290852", code="111111"):
        self.driver.get(login_url)
        self.click(self.login_ph)
        self.sendKeys(self.login_phone, phone)
        self.sendKeys(self.login_code, code)
        self.click(self.login_submit)


if __name__ == "__main__":
    driver = webdriver.Chrome()
    loginin = LoginPage(driver)
    driver.get(login_url)

    loginin.click_ph()
    loginin.input_phone("15823290852")
    loginin.input_code("111111")
    loginin.click_submit()
    sleep(2)
    b = loginin.is_login_success("欢迎登录")
    print(b)
